//
//  CZBaseTableViewController.swift
//  iOSWeibo10
//
//  Created by 李伟鹏 on 16/5/10.
//  Copyright © 2016年 itcast. All rights reserved.
//

import UIKit

class CZBaseTableViewController: UITableViewController {

    var useLogin: Bool = CZUserAccountViewModel.sharedInstance.isUserLogin
    override func loadView() {
        if useLogin {
            super.loadView()
        }else{
            view = visitorView
            visitorView.delegate = self
            if self is CZHomeViewController{
                visitorView.startRotationAnimation()
            }else if self is CZMessageViewController{
  visitorView.setupVisitorInfo("visitordiscover_image_message", message: "登录后，别人评论你的微博，发给你的消息，都会在这里收到通知")
            }else if self is CZDiscoveryViewController {
                visitorView.setupVisitorInfo("visitordiscover_image_message", message: "登录后，最新、最热微博尽在掌握，不再会与实事潮流擦肩而过")
            } else if self is CZProfileViewController {
                visitorView.setupVisitorInfo("visitordiscover_image_profile", message: "登录后，你的微博、相册、个人资料会显示在这里，展示给别人")
            }
            self.navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self, action: "visitorViewDidClickRegister")
            self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: UIBarButtonItemStyle.Plain, target: self, action: "visitorViewDidClickLogin")
        }
    }

    lazy var visitorView: CZVisitorView = CZVisitorView()

}

extension CZBaseTableViewController: CZVisitorViewDelegate{
    func visitorViewDidClickRegister() {
        print(__FUNCTION__)
    }
    
    func visitorViewDidClickLogin() {
        let oauthVc = CZOauthViewController()
        let nav = UINavigationController(rootViewController: oauthVc)
        self.presentViewController(nav, animated: true, completion: nil)
    }
}
